/*
 * @(#)PdqSupplierClient.java
 * Date 2013-12-06
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.pdq.client;

import javax.inject.Inject;

import javax.xml.ws.BindingProvider;

import javax.xml.ws.soap.AddressingFeature;

import ihe.iti.pdqv3._2007.PDQSupplierPortType;
import ihe.iti.pdqv3._2007.PDQSupplierService;

import org.hl7.v3.PRPAIN201305UV02;
import org.hl7.v3.PRPAIN201305UV02QUQIMT021001UV01ControlActProcess;
import org.hl7.v3.PRPAMT201306UV02ParameterList;
import org.hl7.v3.PRPAMT201306UV02QueryByParameter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import us.hornerscorners.lamppost.config.EndpointConfig;

import us.hornerscorners.lamppost.hl7v3common.transformer.CDTransformer;
import us.hornerscorners.lamppost.hl7v3common.transformer.CSTransformer;
import us.hornerscorners.lamppost.hl7v3common.transformer.IITransformer;
import us.hornerscorners.lamppost.hl7v3common.transformer.TSTransformer;

import us.hornerscorners.lamppost.hl7v3common.utils.HL7Utils;

import us.hornerscorners.lamppost.ws.AbstractWSClient;


/**
 * Class description
 *
 *
 * @version        v1.0, 2013-12-06
 * @author         Jim Horner
 */
public class PdqSupplierClient extends AbstractWSClient {

    /** Field description */
    @Inject
    private CDTransformer cdTransformer;

    /** Field description */
    @Inject
    private CSTransformer csTransformer;

    /** Field description */
    @Inject
    private IITransformer iiTransformer;

    /** Field description */
    private final Logger logger = LoggerFactory.getLogger(getClass());

    /** Field description */
    private final PDQSupplierService service;

    /** Field description */
    @Inject
    private TSTransformer tsTransformer;

    /**
     * Constructs ...
     *
     *
     * @param config
     */
    public PdqSupplierClient(EndpointConfig config) {

        super(config);
        this.service = new PDQSupplierService();
    }

    /**
     * Method description
     *
     * @param params
     */
    public void findCandidates(PRPAMT201306UV02ParameterList params) {

        PDQSupplierPortType port =
            this.service.getPDQSupplierPortSoap12(new AddressingFeature(true, true));

        configureBindingProvider(null, (BindingProvider) port);

        PRPAIN201305UV02 request = new PRPAIN201305UV02();

        PRPAIN201305UV02QUQIMT021001UV01ControlActProcess controlProcess =
            request.getControlActProcess();

        PRPAMT201306UV02QueryByParameter query = new PRPAMT201306UV02QueryByParameter();
        query.setParameterList(params);

        controlProcess
            .setQueryByParameter(
                HL7Utils.hl7Factory
                    .createPRPAIN201306UV02MFMIMT700711UV01ControlActProcessQueryByParameter(
                        query));

        port.pdqSupplierPRPAIN201305UV02(request);
    }
}
